"""
@name : 09-多进程-multiprocess
@author : wenyao
@projectname: xsfh
"""
from multiprocessing import Process, current_process
import time

lst = []
def task(i):
    print(current_process().name, i, 'start.....')
    time.sleep(2)
    lst.append(i)
    print(lst)
    print(current_process().name,i ,"end.....")

if __name__ == "__main__":
    p_lst = []
    for i in range(4):
        p = Process(target=task, args=(i,))
        p_lst.append(p)
        p.start()

    for p in p_lst:
        p.join()
    print("main  end........")
#各个进程都拥有一份独立的数据，互相隔离

#自定义进程类
import multiprocessing
class MyProcess(multiprocessing.Process):
    def __init__(self,num):
        super().__init__()
        self.num = num
    def run(self):
        print(f"running on numbers:{self.num}")
if __name__ == '__main__':
    t1 = MyProcess(1)
    t2 = MyProcess(2)
    t1.start()
    t2.start()